<?php
declare (strict_types = 1);

namespace app\store\controller;

use app\store\model\CarType as CarTypeModel;

class CarType extends Controller
{
    public function list()
    {
        $model = new CarTypeModel;
        $list = $model->getList();
        return $this->renderSuccess(compact('list'));
    }

    public function add()
    {
        // 新增记录
        $model = new CarTypeModel;
        if ($model->add($this->postForm())) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }

    public function edit(int $carTypeId)
    {
        // 分类详情
        $model = CarTypeModel::get($carTypeId);
        // 更新记录
        if ($model->edit($this->postForm())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }

    // public function delete(int $carTypeId)
    // {
    //     $model = CarTypeModel::get($carTypeId);
    //     if (!$model->remove($carTypeId)) {
    //         return $this->renderError($model->getError() ?: '删除失败');
    //     }
    //     return $this->renderSuccess('删除成功');
    // }
}
